package com.ali.springcloud;

import com.ali.springcloud.entities.CommonResult;
import com.ali.springcloud.entities.Payment;
import com.ali.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：ALi
 * @date ：Created in 2022/6/30 16:50
 * @description：payment业务类
 * @modified By：
 * @version: $
 */
@RestController
@Slf4j
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    //新增
    @PostMapping(value = "/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        boolean save = paymentService.save(payment);
        log.info("********插入结果为："+save);
        return save==true?new CommonResult(200,"插入数据库成功,serverPort:"+serverPort,save):new CommonResult(444,"插入数据失败",null);
    }
    //查询
    @GetMapping(value = "/payment/get/{id}")
    public CommonResult getById(@PathVariable("id") Long id){
        Payment payment1 = paymentService.getById(id);
        log.info("********插入结果为："+payment1);
        return payment1 != null?new CommonResult(200,"查询数据库成功,serverPort:"+serverPort,payment1):new CommonResult(444,"查询数据失败，查询id："+id,null);
    }
    @GetMapping("/payment/lb")
    public String getPaymentLB() {
        return serverPort;
    }
}